﻿<?php
//header("Content-type: text/html;charset=gbk");//输出编码,避免中文乱码
require_once (dirname(__FILE__) . "/../include/common.inc.php");
if(isset($_POST["page"])){
	// 总行数 $pageMount
	// 当前页数 $page
	// 每页显示条数$PageSize
	// 总页数 PageCount
	$pageSize = 10;
    $sql = "SELECT count(*)  FROM dede_archives t1 LEFT JOIN dede_addon4sks t2 ON t1.id = t2.aid left join dede_sys_enum t3 on t2.area = t3.disorder  WHERE t3.egroup='area' and t2.typeid='12'";

    $con = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);
	mysql_select_db($cfg_dbname, $con);
	mysql_query("SET NAMES ".$cfg_db_language); 
	
   $result = mysql_query($sql);
    $row = mysql_fetch_row($result);
    $pageMount = $row[0];
    //echo '$pageMount====='.$pageMount;
	//echo 'page==='.$_POST["page"];
	@$page = max(1, intval($_POST["page"]));
	
	//echo '$page==='.$page;
    $mysql = "SELECT t1.id,t1.title,t3.ename as area,t2.shopName,t2.address,t2.saleshotline ,t2.mouthword FROM dede_archives t1 LEFT JOIN dede_addon4sks t2 ON t1.id = t2.aid left join dede_sys_enum t3 on t2.area = t3.disorder  WHERE t3.egroup='area' and t2.typeid='12' limit  ".($page-1)*($pageSize).",".$pageSize;
    // echo $mysql;
	
	
    $query = mysql_query($mysql); 
    $divStr = '<div class="list mb8">
            	   <table width="100%" border="0" cellspacing="0" cellpadding="0">
					  <tr>
						<th class="t_1">店名</th>
						<th>地址</th>
						<th>销售热线</th>
						<th class="t_2">口碑</th>
					  </tr>';
					  
	    $odd = 1; // 奇偶行显示不同的眼神 
		while($row = mysql_fetch_array($query,MYSQL_ASSOC)) {
		     $odd ++;
			 $articles[] = array('id'=>$row['id'],'title'=>$row['title']);
			 if($odd%2 == 0) {
			    $divStr.= '<tr class="gray">';
			 } else {
				$divStr.= '<tr >';
			 }
			 $divStr.=' <td><a href="./view.php?aid='.$row["id"].'" target="_blank"><strong>'.$row["title"].'</strong></a></td>
						<td>'.$row["address"].'</td>
						<td>'.$row["saleshotline"].'</td>
						<td class="t_cen">'.$row["mouthword"].'</td>
				   </tr>';
		}
		$divStr.= '  </table>
				 </div>';
		
		 // 总页数 = 总行数/每页行数
	     $PageCount = ceil($pageMount/$pageSize);
		 if($page>$PageCount|$page==0){
 		     echo "暂无数据......"; 
             exit();
         }

	       /*<div class="pager">
                	<ul>
                    	<li><a href="#" class="next">下一页</a></li>
                        <li><a href="#">n</a></li>
                        <li class="dot"><a href="#">...</a></li>
                        <li><a href="#">3</a></li>
                        <li><a href="#">2</a></li>
                        <li class="selected"><a href="#">1</a></li>
                    	<li class="last_dis">上一页</li>
                    </ul>
                </div>*/
		  $page_str = '<div class="pager">
                	     <ul>';
          $PageOut = '';
          if($page==1){ // 如果只有一页 
			  $PageOut .= '<li  class="last_dis">首页</li><li class="last_dis">上一页</li>';
          } else{
              $PageOut .= '<li class="last_dis"><a href="javascript:void(0)" onclick=changepage("1")>首页</a>';
			  $PageOut .= '<li class="last_dis"><a href="javascript:void(0)" onclick=changepage("'.($page-1).'")>上一页</a></li>';
          }
		  
		  
		  
          if($page==$PageCount||$PageCount==0){
              $PageOut .= '';
          }
          else{
              $PageOut .=  '<li ><a class="next" href="javascript:void(0)" onclick=changepage("'.($page+1).'")>下一页</a></li>';
			  $PageOut .=  '<li ><a class="next" href="javascript:void(0)" onclick=changepage("'.$PageCount.'")>尾页</a></li>';
          }

		 $page_str.= $PageOut;
	     $page_str.= '<li class="selected">总'.$pageMount.'页 每页'.$pageSize.'条数据 共'.$PageCount.'页</li>';
         $page_str.='</ul>
                 </div>';
   // }	
		echo $divStr;
		echo $page_str;
	mysql_close($con);
    
}else{
    die();
}

/*
if(isset($_POST["page"])){
    @$page = max(1, intval($_POST["page"]));
    $pagesize=10;
    $startindex=($page-1)*$pagesize;
    $sql="SELECT * FROM test ORDER BY id LIMIT $startindex,$pagesize";
    $rec=mysql_query($sql);
    while($row=mysql_fetch_array($rec)){
        $str.="<li>".$row["uname"]."</li>";
    }
    $num=mysql_num_rows(mysql_query("select * from test"));
    $pagenum=@ceil($num/$pagesize);
    for($i=1;$i<=$pagenum;$i++){
        if($page==$i){
            $str.="<a href='javascript:void(0)' onclick=changepage(".$i.")>[".$i."]</a>&nbsp;&nbsp;&nbsp;";
        }else{
            $str.="<a href='javascript:void(0)' onclick=changepage(".$i.")>".$i."</a>&nbsp;&nbsp;&nbsp;";
        }
    }
    echo $str;
}else{
    die();
}*/
?>

